//
//  MineWalletWithdrawPopView.m
//  copyrightTrading
//
//  Created by 郭子一 on 2020/10/6.
//  Copyright © 2020 郭子一. All rights reserved.
//

#import "MineWalletWithdrawPopView.h"

@interface MineWalletWithdrawPopView ()
@property (nonatomic, strong) InsetsTextField *withdrawTextF;
@property (nonatomic, strong) InsetsTextField *cardNumTextF;
@end

@implementation MineWalletWithdrawPopView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    self.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    
    UIView *bgView = [UIView new];
    bgView.backgroundColor =  RGB_VALUE(0x000000);
    bgView.alpha = 0.4;
    [self addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.offset(0);
    }];
    
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = UIColor.whiteColor;
    view.layer.cornerRadius = 12;
    view.layer.masksToBounds = YES;
    [self addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(16);
        make.right.offset(-16);
        make.center.offset(0);
        make.height.mas_equalTo(300);
    }];
    
    UILabel *titleLabel = [UILabel new];
    titleLabel.text = @"绑定银行卡";
    titleLabel.font = JSS_MEDIUM_FONT(17);
    titleLabel.textAlignment = NSTextAlignmentCenter;
    [view addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(39);
        make.centerX.offset(0);
        make.width.mas_equalTo(135);
        make.height.mas_equalTo(24);
    }];
    
    UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [closeBtn setImage:[UIImage imageNamed:@"popViewClose"] forState:UIControlStateNormal];
    [closeBtn addTarget:self action:@selector(closeBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:closeBtn];
    [closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-27);
        make.top.offset(24);
        make.width.height.mas_equalTo(24);
    }];
    
    self.withdrawTextF = [[InsetsTextField alloc] init];
    self.withdrawTextF.placeholder = @"输入提现金额";
    self.withdrawTextF.font = JSS_MEDIUM_FONT_2;
    self.withdrawTextF.textColor = RGB_VALUE(0x6F6F6F);
    self.withdrawTextF.layer.masksToBounds = YES;
    self.withdrawTextF.layer.cornerRadius = 12;
    self.withdrawTextF.backgroundColor = RGB_VALUE(0xE6E6E6);
    [view addSubview:self.withdrawTextF];
    [self.withdrawTextF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(17);
        make.top.equalTo(titleLabel.mas_bottom).offset(15);
        make.right.offset(-17);
        make.height.mas_equalTo(51);
    }];
    
    self.cardNumTextF = [[InsetsTextField alloc] init];
    self.cardNumTextF.placeholder = @"输入提现金额";
    self.cardNumTextF.font = JSS_MEDIUM_FONT_2;
    self.cardNumTextF.textColor = RGB_VALUE(0x6F6F6F);
    self.cardNumTextF.layer.masksToBounds = YES;
    self.cardNumTextF.layer.cornerRadius = 12;
    self.cardNumTextF.backgroundColor = RGB_VALUE(0xE6E6E6);
//    self.cardNumTextF.rightView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"unionPay"]];
    [self.cardNumTextF setRightViewWithImageName:@"unionPay" size:CGSizeMake(32, 20)];
    [view addSubview:self.cardNumTextF];
    [self.cardNumTextF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(17);
        make.top.equalTo(self.withdrawTextF.mas_bottom).offset(10);
        make.right.offset(-17);
        make.height.mas_equalTo(51);
    }];
    
    UIButton *loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [loginBtn setTitle:@"确定" forState:UIControlStateNormal];
    [loginBtn setTitleColor:RGB_VALUE(0xFFFFFF) forState:UIControlStateNormal];
    [loginBtn.titleLabel setFont:JSS_MEDIUM_FONT_7];
    loginBtn.backgroundColor = RGB_VALUE(0xDC0000);
    loginBtn.layer.masksToBounds = YES;
    loginBtn.layer.cornerRadius = 12;
    [loginBtn addTarget:self action:@selector(loginBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:loginBtn];
    [loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.offset(-30);
        make.right.offset(-81);
        make.left.offset(81);
        make.height.mas_equalTo(51);
    }];
}

// 确定
- (void)loginBtnClick
{
    if ([self.delegate respondsToSelector:@selector(withdrawPopEnsureBtnClick)]) {
        [self.delegate withdrawPopEnsureBtnClick];
    }
    [UIView animateWithDuration:0.1 animations:^{
        self.alpha = 0;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}

- (void)closeBtnClick
{
    [UIView animateWithDuration:0.1 animations:^{
        self.alpha = 0;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}

@end
